import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:im_app/im/page/view/ListSeparator.dart';
import 'package:im_app/im/page/view/LoadingView.dart';
import 'package:im_app/im/page/view/component/cell/SessionItemView.dart';
import 'package:provider/provider.dart';
import '../util/ImSingleton.dart';
import '../util/LoggerUtil.dart';
import 'bloc/SessionListCubit.dart';

/// 会话展示，不使用bloc模式（bloc在频繁刷新时出现数据未变更情况)
class SessionListPage extends StatelessWidget {
  SessionListPage({super.key});

  final _logger = createLogger();

  @override
  Widget build(BuildContext context) {
    var sessionListCubit = context.watch<SessionListCubit>();
    ImSingleton.getInstance().sessionListCubit = sessionListCubit;
    return LoadingView(
        state: sessionListCubit.state.state,
        child: ListView.separated(
          itemCount: sessionListCubit.state.sessions?.length ?? 0,
          itemBuilder: (BuildContext context, int index) {
            return SessionItemView(imSession: sessionListCubit.state.sessions[index]);
          },
          separatorBuilder: (BuildContext context, int index) {
            return ListSeparator();
          },
        ));
  }
}
